Repository navigation
fix(id/web): validate identity endpoint responses before persisting (#7839) - #8505
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c26fce350d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| describe("parseIdentityRegisterResponse (#7839)", () => { | ||
| it("accepts a well-shaped registration", () => { | ||
| expect(parseIdentityRegisterResponse({ token: "tok", client_id: "cid", name: "Ada" })).toEqual({ |
There was a problem hiding this comment.
Cover identity response invariants with property tests
The three new response parsers have meaningful validation invariants, but their tests exercise only fixed examples. Root AGENTS.md explicitly requires property-based coverage for parsers and says example-based tests do not replace it. Add generated JSON inputs with an independent acceptance predicate, checking that invalid shapes throw and valid fields are preserved without coercion; retain these examples as regression cases.
AGENTS.md reference: AGENTS.md:L41-L45
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1f01c77 — property coverage added for all three parsers (seeded generator, 2000 generated inputs per parser, independent acceptance predicates as oracle, no-coercion assertions on accepted inputs). Full detail: #8505 (comment)
|
Fixed in 1f01c77: added property coverage for all three parsers in identity-refresh.test.ts — a seeded generator (mulberry32, failures reproduce from the seed) builds random JSON-shaped payloads (random field subsets across token/client_id/name/extra, random value types including numeric/object/array scalars), 2,000 inputs per parser, checked against independent acceptance predicates written directly from the endpoint contracts (the oracle; no shared code with the parsers). Where the predicate accepts, the test asserts the parsed result preserves the accepted strings verbatim (no coercion); where it rejects, it asserts the parser throws. The fixed examples stay as regression cases. identity-refresh.test.ts now 18/18 pass; tsc --noEmit clean. |
Fixes #7839 (task 14019).
What
pkgs/id/web/src/main.tstrusted the shape of all three identity endpoint responses:data.token/data.client_id/data.nameflowed from an unguardedresp.json()intosaveIdentity, which String()-coerces into localStorage — a wrong-shape 200 persisted a fake'undefined'/'[object Object]'identity, and a wrong-shape/me200 overwrote a valid stored token.Change
src/identity-refresh.ts(home ofidentityNeedsRefresh, pattern:parseUploadResponsefor id(web/image-upload): /api/upload response shape-trusted — a wrong-shape 200 inserts an image node with src undefined into the document #7823): addsparseIdentityMeResponse,parseIdentityRegisterResponse,parseIdentityNameResponse. Plain-object body required; token/client_id non-empty strings when required (register) or present (/me rotation); name string-or-null. Anything else throws.src/main.ts: all three fetch sites parse through the validators, so a wrong-shape body fails through the existing error paths — register returns null without callingsaveIdentity; /me falls back to the stored identity untouched; /name returns null without callingupdateStoredName.Tests
src/identity-refresh.test.tscover{}, null, bare string, array, numeric token, object token/client_id, empty token, and non-string name for register and /me, plus non-string/missing name for /name (oracle: the parser throws, which is what keeps localStorage unchanged). Targeted file: 15/15 pass.tsc --noEmit) clean.search-panel.test.tsrole=search aria-label — verified failing identically on clean main) and 1 flake (tags.test.ts, passes in isolation on both clean main and this branch).Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.